package com.channel.temperature.collect.ui.activity

import android.os.Bundle
import android.util.Log
import com.kongzue.dialogx.dialogs.BottomMenu
import com.kongzue.dialogx.interfaces.OnMenuItemClickListener
import com.channel.temperature.collect.R
import com.channel.temperature.collect.app.base.BaseActivity
import com.channel.temperature.collect.app.ext.initBack
import com.channel.temperature.collect.app.ext.mmkv
import com.channel.temperature.collect.data.annotation.ValueKey
import com.channel.temperature.collect.databinding.ActivityColorSettingBinding
import com.channel.temperature.collect.ui.viewmodel.ColorSettingModel
import me.hgj.mvvmhelper.ext.setOnclickNoRepeat


class ColorSettingActivity : BaseActivity<ColorSettingModel, ActivityColorSettingBinding>() {
    companion object {
        const val TAG = "ColorSettingActivity"
        val colorStringDescList = mutableListOf<String>(
            "红色",
            "橙色",
            "黄色",
            "绿色",
            "青色",
            "蓝色",
            "紫色",
            "粉红色",
            "棕色",
            "灰色",
            "白色",
            "黑色"
        )

    }

    val colorIntList = mutableListOf<Int>(
        R.color.color0,
        R.color.color1,
        R.color.color2,
        R.color.color3,
        R.color.color4,
        R.color.color5,
        R.color.color6,
        R.color.color7,
        R.color.color8,
        R.color.color9,
        R.color.color10,
        R.color.color11
    )

    override fun initView(savedInstanceState: Bundle?) {
        mToolbar.initBack("自定义颜色") {
            finish()
        }
    }

    override fun onRequestSuccess() {
        var color1Index = mmkv.getInt(ValueKey.COLOR1, 0)
        var color2Index = mmkv.getInt(ValueKey.COLOR2, 2)
        var color3Index = mmkv.getInt(ValueKey.COLOR3, 8)
        mBind.color1.setBackgroundColor(resources.getColor(colorIntList[color1Index]))
        mBind.color2.setBackgroundColor(resources.getColor(colorIntList[color2Index]))
        mBind.color3.setBackgroundColor(resources.getColor(colorIntList[color3Index]))
    }

    override fun onBindViewClick() {
        setOnclickNoRepeat(
            mBind.color1,
            mBind.color2,
            mBind.color3,
        ) {
            when (it) {
                mBind.color1 -> {
                    BottomMenu.show(colorStringDescList as List<CharSequence>?)
                        .setMessage("请选择板载温度曲线颜色").onMenuItemClickListener =
                        OnMenuItemClickListener { dialog, text, index ->
                            Log.e("请选择板载温度曲线颜色", "请选择板载温度曲线颜色  " + index)
                            mmkv.putInt(ValueKey.COLOR1, index)
                            mBind.color1.setBackgroundColor(resources.getColor(colorIntList[index]))
                            false
                        }

                }

                mBind.color2 -> {
                    BottomMenu.show(colorStringDescList as List<CharSequence>?)
                        .setMessage("请选择环境温度曲线颜色").onMenuItemClickListener =
                        OnMenuItemClickListener { dialog, text, index ->
                            Log.e("请选择环境温度曲线颜色", "请选择环境温度曲线颜色  " + index)
                            mmkv.putInt(ValueKey.COLOR2, index)
                            mBind.color2.setBackgroundColor(resources.getColor(colorIntList[index]))
                            false
                        }
                }

                mBind.color3 -> {
                    BottomMenu.show(colorStringDescList as List<CharSequence>?)
                        .setMessage("请选择环境压力曲线颜色").onMenuItemClickListener =
                        OnMenuItemClickListener { dialog, text, index ->
                            Log.e("请选择环境压力曲线颜色", "请选择环境压力曲线颜色  " + index)
                            mmkv.putInt(ValueKey.COLOR3, index)
                            mBind.color3.setBackgroundColor(resources.getColor(colorIntList[index]))
                            false
                        }
                }
            }
        }
    }


}